<?php
class cmshopapi_GetCategories extends cmshopApi_base
{
    var $verb='GetCategories';
    var $fields=array(
        
    );
    function Request(){
        if(!$this->checkAuthToken()) throw new Exception_AuthTokenInvalidate('');
        if(isset($this->input['parent_id'])){
            return $this->Response($this->input['parent_id']);
        }
        return false;
    }
    
    // 回给 客户  .
    function Response($parent_id=0,$attach=null){
        //Orders
        if($parent_id==0){
            $cats=Category::all($this->token['store_id']);
        }else{
            $cats=Category::children($this->token['store_id'],$parent_id);
        }
        if(count($cats)){ foreach($cats as $cat){
            $xmlArr_c[]=array(
                'category_id'=>$cat->category_id,
                'parent_id'=>$cat->parent_id,
                'name'=>'<![CDATA['.$cat->name.']]>',
                'leaf'=>$cat->leaf,
            );
        }}
        $xmlArr=array(
            'Ack'=>'Success',
            'timestamp'=>$this->dateTime(),
            'categories'=>$xmlArr_c,
		);
		if(is_array($attach)){
            $xmlArr=$xmlArr+$attach;
        }
        return $this->xmlresponse($xmlArr);
    }
}